package com;

import javax.xml.crypto.Data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Test1 {
    public static void main(String[] args) throws ParseException {
        Date d=new Date();
        String s=Test1.dateTostring(d,"yyyy年MM月dd日 HH:mm:ss");
        System.out.println(s);
        System.out.println("-------------");
        String s1="2048-08-09  12:12:12";
        Date date = Test1.stringToDate(s1, "yyyy-MM-dd HH:mm:ss");
        System.out.println(date);
    }
    public   static String dateTostring(Date date, String s){
        SimpleDateFormat  sdf=new SimpleDateFormat(s);
        String format = sdf.format(date);
        return format;
    }
    public  static  Date  stringToDate(String s,String s1) throws ParseException {
         SimpleDateFormat  sdf=new SimpleDateFormat(s1);
        Date parse = sdf.parse(s);
         return parse;
    }
}
